<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class OemauthMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        $deviceId = $request->header('DEVICEID', '');
        $auth = [
            'f3891740fa2cfdd7'
        ];
        if (!in_array($deviceId, $auth)) {
            return response()->json([
                'code' => Response::HTTP_UNAUTHORIZED,
                'message' => '设备请求不合法',
                'data' => []
            ], Response::HTTP_UNAUTHORIZED);
        }

        return $next($request);
    }
}
